﻿#if false
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using WebSpider.Model;

namespace WebSpider.DataAccess
{
    class VirtualXmlWeb: Web
    {
        XElement xml;
        IEnumerable<Article> _articles;
        public override IEnumerable<Article> Articles
        {
            get
            {
                if (_articles == null)
                {
                    _articles = GetArticles().AsParallel();
                }
                return _articles;
            }
        }
        IEnumerable<Category> _categories;
        public override IEnumerable<Category> Categories
        {
            get
            {
                if (_categories == null)
                {
                    _categories = GetCategories().AsParallel();
                }
                return _categories;
            }
        }
        IEnumerable<WebFile> _files;
        public override IEnumerable<WebFile> Files
        {
            get
            {
                if (_files == null)
                {
                    _files = GetFiles().AsParallel();
                }
                return _files;
            }
        }
        IEnumerable<WebImage> _images;
        override public IEnumerable<WebImage> Images
        {
            get
            {
                if (_images == null)
                {
                    _images = GetImages().AsParallel();
                }
                return _images;
            }
        }


        public VirtualXmlWeb(string name, Stream stream)
        {
            this.xml = XElement.Load(stream);
        }

        public VirtualXmlWeb(string name, XmlReader reader)
        {
            this.xml = XElement.Load(reader);
        }

        public VirtualXmlWeb(string name, XElement xml)
        {
            this.xml = xml;
        }

        public override Web GetValue()
        {
            return ModelXmlSerializer.ToWeb(xml);
        }

        public IEnumerable<Article> GetArticles()
        {
            var a = xml.Element("articles");
            return from el in a.Elements("article")
                   select ModelXmlSerializer.ToArticle(el, Categories);
        }

        public IEnumerable<Category> GetCategories()
        {
            var a = xml.Element("categories");
            return from el in a.Elements("category")
                   select ModelXmlSerializer.ToCategory(el);
        }

        public IEnumerable<WebFile> GetFiles()
        {
            var a = xml.Element("files");
            return from el in a.Elements("file")
                   select ModelXmlSerializer.ToWebFile(el);

        }

        public IEnumerable<WebImage> GetImages()
        {
            var a = xml.Element("images");
            return from el in a.Elements("image")
                   select ModelXmlSerializer.ToWebImage(el);
        }
    }
}
#endif
